<?php

namespace app\apiadmin\controller\live;

use app\apiadmin\model\log\TcPlayerModel;
use think\facade\Db;
use app\common\utils\Res;
use app\common\controller\BaseController;


class Log extends BaseController
{
    // 登录错误日志
    public function addLoginErrorLog()
    {
        $params = $this->request->post();
        $params['add_time'] = date('Y-m-d H:i:s', time());
        $retAdd = Db::table('xh_siyu_live_login_log')->insert($params);
        return Res::ok($retAdd);
    }
    
    // 直播端-播放错误日志
    public function addTcPlayerErrorLog()
    {
        $params = $this->request->post();
        $params['add_time'] = date('Y-m-d H:i:s', time());
        $retAdd = Db::table('xh_siyu_live_tc_player_log')->insert($params);
        return Res::ok($retAdd);
        
    }

    // 直播端-播放日志
    public function viewTcPlayerErrorLog()
    {
        $param = $this->request->post();
        $limit = (int)$param['pageSize'];
        $offset = ($param['pageNumber']-1)*$limit;
        $map=[];
        if($param['live']){
            $map[]=['live', '=', $param['live']];
        }
        if($param['network_type']){
            $map[]=['network_type', '=', $param['network_type']];
        }
        if($param['user_phone']){
            $map[]=['user', 'like', '%"phone":"'.$param['user_phone'].'"%'];
        }
        if($param['user_nickname']){
            $map[]=['user', 'like', '%"nickname":"'.$param['user_nickname'].'"%'];
        }
        if($param['user_open_id']){
            $map[]=['user', 'like', '%"openid":"'.$param['user_open_id'].'"%'];
        }
        if($param['user_union_id']){
            $map[]=['user', 'like', '%"unionid":"'.$param['user_union_id'].'"%'];
        }
        $result = TcPlayerModel::pageMap($map,$offset,$limit);
        $total = TcPlayerModel::pageMapCount($map);
        $data=[
            'list'=>$result,
            'total'=>$total
        ];
        return Res::ok($data);

    }
     
    

}